exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseSocket {
    __before() {
        this.testKey = 'testkey';
    }

    /**
     * 新增或更新部件
     */
    doAddOrUpdateAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this.service('cms/PartsService');
            const res = yield CmsService.doAddOrUpdate(_this.post());
            return _this.json(res);
        })();
    }

    /**
     * 删除部件
     */
    doDelAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this2.service('cms/PartsService');
            const res = yield CmsService.delParts(_this2.post());
            return _this2.json(res);
        })();
    }

    /**
     * 保存图片
     */
    doUploadImgAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this3.service('cms/PartsService');
            const file = _this3.file('image');
            const postData = _this3.post();
            let aj = think.ajaxJson();
            // console.log("file:", file);
            if (file) {
                //保存图片
                console.log('图片接口请求');
                const pathObj = yield _this3.renameFile(file);
                const res = yield CmsService.uploadImg(pathObj);
                return _this3.json(res);
            } else {
                aj.success = false;
                aj.msg = "文件请求失败";
                return _this3.json(aj);
            }
        })();
    }

    /**
     * 批量删除部件
     */
    doBatchDelAction() {}

    /**
     * 分页查询部件列表
     */
    queryPartsListAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this4.service('cms/PartsService');
            const res = yield CmsService.getPartsList(_this4.post());
            return _this4.json(res);
        })();
    }

    /**
     * 查询所有部件信息
     *
     * @returns
     */
    queryPartsAllListAction() {
        var _this5 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this5.service('cms/PartsService');
            const res = yield CmsService.getPartsAllList();
            return _this5.json(res);
        })();
    }

    /**
     * 查询部件与部件分类信息
     *
     * @returns
     */
    queryPartsAndGroupInfoAction() {
        var _this6 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this6.get('page,pageSize');
            const CmsService = _this6.service('cms/PartsService');
            const res = yield CmsService.getPartsAndGroupInfo(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this6.json(aj);
        })();
    }

    queryPartCountAction() {
        var _this7 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const CmsService = _this7.service('cms/PartsService');
            const res = yield CmsService.getPartCount();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this7.json(aj);
        })();
    }

    queryBadPartsAndGroupInfoAction() {
        var _this8 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this8.post();
            const CmsService = _this8.service('cms/PartsService');
            const res = yield CmsService.getBadPartsAndGroupInfo(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this8.json(aj);
        })();
    }

    /**
     * 查询部件
     */
    queryPartsAction() {
        var _this9 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this9.service('cms/PartsService');
            const postData = {
                id: _this9.post('id')
            };
            const res = yield CmsService.getParts(postData);
            return _this9.json(res);
        })();
    }

    queryPartOneInfoAction() {
        var _this10 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this10.service('cms/PartsService');
            const postData = {
                id: _this10.post('id')
            };
            const res = yield CmsService.getPartOneInfo(postData);
            return _this10.json(res);
        })();
    }

    /**
     * 查询损害的部件
     * @returns {Response | *}
     * @private
     */
    queryBadPartsAction() {
        var _this11 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this11.post('ObjState');
            const CmsService = _this11.service('cms/PartsService');
            const res = yield CmsService.getBadParts(data);
            console.log('95', res);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this11.json(aj);
        })();
    }

    /**
     * 添加所属单元格id:BGID
     */

    addPartBGIDAction() {
        var _this12 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const BGIDService = _this12.service('cms/PartsService');
            const res = yield BGIDService.partsBGID(_this12.post());
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '保存失败';
            }

            return _this12.json(aj);
        })();
    }

    __call() {
        return this.redirect('/www.baidu.com');
    }
};